$(document).ready(function() {
	
	//Download file ajax
	$('.download_button').live('click',function(){
		return;
		if( check_login ){
			$.ajax({
				url: base_url + 'download/ajax_update_product',
				type: "POST",
				data: '',
				dataType: "json",
				success: function(msg){
					if( msg ){
						if( msg.status == 'ok' ){
							$('#gold_number').html( msg.gold_number );
						}
					}
				}
			});				
		}
	});
	
	//Check validate key_search
	$("#search_submit").click(function() {
		var search = $("#search_key").attr('value');
		search = $.trim(search);
		if (search == null || search == "" || search == str) {
			alert( str_alert );
			$("#key").focus();
			return false;
		}
	});	
	
	//Search key default for search form
	$('.auto_text').css('color', '#999').focus(function() {
		if ($(this).val() == str)
			$(this).css('color', '#000').val('').addClass('focus');
	}).blur(function() {
		if (jQuery.trim($(this).val()) == "") {
			$(this).css('color', '#999').val(str).removeClass('focus');
		}
	});
	if ($('#search_key').val() && $('#search_key').val() != str)
		$('input:text').css('color', 'black');	
	
	
	/***Javascript for popup tag search***/
	//Requirement: press key up, key down
	$(document).ready(function() {
		hoverFunction = function() {
			$('.link_tab').removeClass('kind_hover');
			tab_index = parseInt($(this).attr('tabindex'));
			$("a.link_tab[tabindex='" + tab_index + "']").addClass('kind_hover').focus();
		};

		$("a.link_tab[tabindex='1000']").focus();
		tab_index = 1000;
		//set default tabindex when search complete
		check_keyDown = false;

		//Controll keypress in popup
		$(document).keydown(function(e) {
			//Get max tab index
			var maxtab = 0;
			$('.link_tab').each(function() {
				var tabindex = $(this).attr('tabindex');
				if (tabindex > maxtab)
					maxtab = tabindex;
			});

			var keyCode = e.keyCode || e.which;
			var arrow = {
				left : 37,
				up : 38,
				right : 39,
				down : 40
			};

			switch (keyCode) {
				//Press key up
				case arrow.up:
					if (tab_index > 1000) {
						tab_index--;
						//check value min

						//Controll scroll of popup window
						e.preventDefault();
					}
					break;

				//Press key down
				case arrow.down:
					if (tab_index < maxtab) {
						tab_index++;
						//check value max

						//Controll scroll of popup window
						e.preventDefault();
					}
					break;
			}

			if (keyCode == arrow.up || keyCode == arrow.down) {
				$('.link_tab').removeClass('kind_hover');
				$("a.link_tab[tabindex='" + tab_index + "']").addClass('kind_hover').focus();

				//cancel hover when press key
				$(".link_tab").die("hover", hoverFunction);
			}
		});
		//End controll keypress in popup

		//Controll hover

		$(".link_tab").live("hover", function(){
			console.log(1);
		});

		$(".lightBoxList02").live("mouseover", function() {
			$(".link_tab").live("hover", hoverFunction);
		});
		// End Controll hover

		//Prevent tab event focus in list kind of popup
		$('a.link_tab').live('keydown', function(e) {
			var keyCode = e.keyCode || e.which;
			if (keyCode == 9) {
				e.preventDefault();
			}
		});
		
		//Show popup search by tag
		$('#list_tag').click(function(){
			$('#mypopup_list_tag').modal();
			return false;
		});
		
		//Show popup search by supplier
		$('#list_supplier').click(function(){
			$('#mypopup_list_supplier').modal();
			return false;
		});	

	});
	/***End javascript for popup tag search***/
});

/*********Js for top button************/
$(function() {
	$.fn.scrollToTop = function() {
		$(this).hide().removeAttr("href");
		if ($(window).scrollTop() != "0") {
			$(this).fadeIn("slow")
		}
		scrollDiv = $(this);
		$(window).scroll(function() {
			if ($(window).scrollTop() == 0) {
				$(scrollDiv).fadeOut("slow")
			} else {
				$(scrollDiv).fadeIn("slow")
			}
		});
		$(this).live('click',function() {
			$("html, body").animate({
				scrollTop : 0
			}, "slow")
		})
	}
});

$(function() {
	//Scroll to top
	$("#toTop").scrollToTop();
	$('.tag').css({
		'height' : '20px',
		'overflow' : 'hidden'
	});

	//Add arrow to multi ul
	//$("ul li:has(ul)").addClass("down");
});	
/************End js for top button************/